
//
//  ConOrReViewController.m
//  Luxury
//
//  Created by DCQ on 2018/5/22.
//  Copyright © 2018年 ZNXZ. All rights reserved.
//

#import "ConOrReViewController.h"
#import "ConOrReListViewController.h"
 
#import "LLSegmentBar.h"
@interface ConOrReViewController ()<LLSegmentBarDelegate>
@property(nonatomic, assign) ConOrReViewStyle  viewStyle;
@property (nonatomic,strong) LLSegmentBar * segmentBar;
@end

@implementation ConOrReViewController
- (instancetype)initWithStyle:(ConOrReViewStyle) style{
    self = [super init];
    if (self) {
        self.viewStyle = style;
    }
    return self;
}

- (LLSegmentBar *)segmentBar{
    if (!_segmentBar) {
        LLSegmentBar *segmentBar = [LLSegmentBar segmentBarWithFrame:self.view.bounds];
        segmentBar.delegate = self;
       
        [self.view addSubview:segmentBar];
        _segmentBar = segmentBar;
    }
    return _segmentBar;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavigationBar];
    [self setupXLTabIndicator];
}
- (void)setupNavigationBar{
    // 1 设置segmentBar的frame
    self.segmentBar.frame = CGRectMake(100, 0, [UIScreen mainScreen].bounds.size.width -200, 35);
    NSArray *items = @[@"回收", @"寄卖"];
    self.segmentBar.items = items;
    self.navigationItem.titleView = self.segmentBar;
    [self.segmentBar updateWithConfig:^(LLSegmentBarConfig *config) {
        config.itemNormalColor(UIColorFromRGB(0x333333)).itemSelectColor(UIColorFromRGB(0xAD9B6A)).indicatorColor(UIColorFromRGB(0xAD9B6A)).indicatorExtraW(-10).segmentBarBackColor([UIColor clearColor]);
        
    }];
    if (self.viewStyle == ConOrReViewStyle_recycle) {
        self.segmentBar.selectIndex = 0;
    }else if (self.viewStyle == ConOrReViewStyle_consign){
        self.segmentBar.selectIndex = 1;
        
    }
   
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)setupXLTabIndicator{
    
    self.buttonBarView.shouldCellsFillAvailableWidth = YES;
 
    self.isProgressiveIndicator = YES;
    self.isElasticIndicatorLimit = YES;
    self.buttonBarView.selectedBar.backgroundColor =  UIColorFromRGB(0xAD9B6A);
    self.buttonBarView.isAutoIndicatorWidth = NO;
    self.buttonBarView.indicatorWidth = 20;
    self.buttonBarView.selectedBarAlignment = XLSelectedBarAlignmentCenter;
    self.buttonBarView.backgroundColor = [UIColor whiteColor];
    self.bottomLineView.backgroundColor =  UIColorFromRGB(0xECEEEE);
    self.buttonBarView.bottomLineHeight = 1;
 
    
}
-(NSArray *)childViewControllersForPagerTabStripViewController:(XLPagerTabStripViewController *)pagerTabStripViewController{
    ConOrReVCType  vcType =  ConOrReVCType_normal;
    if (self.viewStyle == ConOrReViewStyle_recycle) {
        vcType = ConOrReVCType_recycling;
    }else if (self.viewStyle == ConOrReViewStyle_consign){
        vcType = ConOrReVCType_consignment;
        
    }
    
    ConOrReListViewController * oneVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_all withType:vcType];
    ConOrReListViewController * twoVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_waitOffer withType:vcType];
    ConOrReListViewController * threeVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_alreadyOffer withType:vcType];
    ConOrReListViewController * fourVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_alreadySend withType:vcType];
    ConOrReListViewController * fiveVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_sell withType:vcType];
    
    ConOrReListViewController * sixVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_complete withType:vcType];
    ConOrReListViewController * sevenVC = [[ConOrReListViewController alloc]initWithStyle:ConOrReTableViewControllerStyle_cancel withType:vcType];
    NSArray * childViewControllers = @[];
    if (self.viewStyle == ConOrReViewStyle_recycle) {
        childViewControllers = [NSMutableArray arrayWithObjects:oneVC,twoVC,threeVC,fourVC,sixVC,sevenVC,nil];
    }else if(self.viewStyle == ConOrReViewStyle_consign){
        childViewControllers = [NSMutableArray arrayWithObjects:oneVC,twoVC,threeVC,fourVC,fiveVC,sixVC,sevenVC,nil];
    }
    
    return childViewControllers;
}
- (void)segmentBar:(LLSegmentBar *)segmentBar didSelectIndex:(NSInteger)toIndex fromIndex:(NSInteger)fromIndex{
    self.currentIndex = 0;
    if (toIndex == 0) {
        self.viewStyle = ConOrReViewStyle_recycle;
    }else if(toIndex == 1){
        self.viewStyle = ConOrReViewStyle_consign;
        
    }
    [self reloadPagerTabStripView];
}

- (UIColor *)getTabTitleColorSelected{
    
    return UIColorFromRGB(0xAD9B6A);
}
- (UIColor *)getTabTitleColorNor{
    return  UIColorFromRGB(0x333333);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
